//package com.bestcem.xm.wallet.mq.receive;
//
//import com.alibaba.fastjson.JSON;
//import com.bestcem.xm.common.core.uitls.MsgPackFormatUtil;
//import com.bestcem.xm.wallet.mq.WalletTopics;
//import com.bestcem.xm.wallet.mq.dto.LimitOrderStatusPollMessage;
//import com.bestcem.xm.wallet.mq.dto.LimitOrderTimeoutMessage;
//import com.bestcem.xm.wallet.service.OrgWalletMqService;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.util.Base64;
//
///**
// * 企业钱包消息接收(包括延时消息)
// *
// * @author wangyunyun <yunyun.wang@idiaoyan.com>
// * @version v1.0
// * @date 2022/5/16 18:40
// */
//@Slf4j
//@Component("orgWalletDelayMqReceive")
//public class WalletMqReceive {
//
//    @Resource
//    private OrgWalletMqService orgWalletMqService;
//
//    /**
//     * 监听 企业钱包 延时队列MQ
//     *
//     * @param dto 消息实体
//     * @param channel 消息通道
//     * @author wangyunyun <yunyun.wang@idiaoyan.com>
//     * @date 2022/5/17 14:40
//     */
//    @RabbitListener(queues = {"#{appWalletDelayQueue.name}"}, concurrency = "${app.wallet.rabbitmq.notice-task-concurrency:5}")
//    @RabbitHandler
//    public void handleNoticeTask(Message dto, Channel channel) {
//        try {
//            MsgPackFormatUtil.MqMessage mqMessage = MsgPackFormatUtil.mqDecode(dto.getBody());
//            if (mqMessage == null) {
//                log.error("[WALLET] 自发自收任务mq消息解析失败:{}", Base64.getEncoder().encodeToString(dto.getBody()));
//                channel.basicNack(dto.getMessageProperties().getDeliveryTag(), false, false);
//                return;
//            }
//            if (log.isInfoEnabled()) {
//                log.info("[WALLET] 自发自收任务mq消息:{}", JSON.toJSONString(mqMessage));
//            }
//            if (WalletTopics.LIMIT_ORDER_TIMEOUT_HANDLE.equals(mqMessage.getTopic())) {
//                // 限制充值订单过期处理
//                LimitOrderTimeoutMessage limitOrderTimeoutMessage = MsgPackFormatUtil.mapToObj(mqMessage.getData(), LimitOrderTimeoutMessage.class);
//                orgWalletMqService.handleLimitOrderTimeout(limitOrderTimeoutMessage);
//            } else if (WalletTopics.LIMIT_ORDER_STATUS_POLL.equals(mqMessage.getTopic())) {
//                // 超时查询限制充值订单状态
//                LimitOrderStatusPollMessage limitOrderTimeoutMessage = MsgPackFormatUtil.mapToObj(mqMessage.getData(), LimitOrderStatusPollMessage.class);
//                orgWalletMqService.pollLimitOrderStatus(limitOrderTimeoutMessage);
//            } else {
//                log.error("[WALLET] 消费WALLET 自发自收mq消息失败:{}", Base64.getEncoder().encodeToString(dto.getBody()));
//            }
//
//            channel.basicAck(dto.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            log.error("[WALLET] 处理WALLET队列消息异常:" + Base64.getEncoder().encodeToString(dto.getBody()), e);
//            try {
//                channel.basicNack(dto.getMessageProperties().getDeliveryTag(), false, false);
//            } catch (IOException ex) {
//                log.error("[WALLET] nack消息异常", ex);
//            }
//        }
//    }
//}
